var app = getApp();
Page({
    data: {
        params: {
            height: "160",
            weight: "50",
            station_layout: "",
            abdomen: "",
            type_version: "",
            is_in: "",
            open_id: ""
        },
        shape_list: [
            {
                title: "normals",
                title_cn: "正常",
                img_url: "../../images/normals.jpg"
            }, {
                title: "raised_chest",
                title_cn: "挺胸",
                img_url: "../../images/tingxiong.jpg"
            }, {
                title: "humpbacked",
                title_cn: "驼背",
                img_url: "../../images/tuobei.jpg"
            }
        ],
        abdomen_list: [
            {
                title: "flat_belly",
                title_cn: "平腹",
                img_url: "../../images/flat_belly.jpg"
            }, {
                title: "micro_abdominal",
                title_cn: "微腹",
                img_url: "../../images/micro_abdominal.jpg"
            }, {
                title: "upper_abdomen",
                title_cn: "大腹",
                img_url: "../../images/upper_abdomen.jpg"
            }
        ],
        version_list: [
            {
                title: "slin",
                title_cn: "修身",
                img_url: "../../images/slin.jpg"
            }, {
                title: "fit",
                title_cn: "合身",
                img_url: "../../images/fit.jpg"
            }, {
                title: "loosen",
                title_cn: "宽松",
                img_url: "../../images/loose.jpg"
            }
        ],
        is_in_list: [
            {
                title: "1",
                title_cn: "束在裤子里",
                img_url: "../../images/1.1.jpg"
            }, {
                title: "2",
                title_cn: "放在裤子外",
                img_url: "../../images/2.1.jpg"
            }
        ]
    },
    onReady: function () {
        var _this = this;
        wx.getStorage({
            key: 'loginInfo',
            success: function (res) {
                _this.data.params.open_id = res.data.data.data.openid;
            },
        })
    },
    height_slider: function (e) {
        this.data.params.height = e.detail.value;
    },
    weight_slider: function (e) {
        this.data.params.weight = e.detail.value;
    },
    shape: function (e) {
        var _this = this;
        this.data.params.station_layout = e.currentTarget.dataset.title;
        _this.setData({
            station_layout: e.currentTarget.dataset.title
        })
    },
    abdomen: function (e) {
        var _this = this;
        this.data.params.abdomen = e.currentTarget.dataset.title;
        _this.setData({
            abdomen: e.currentTarget.dataset.title
        })
    },
    version: function (e) {
        var _this = this;
        this.data.params.type_version = e.currentTarget.dataset.title;
        _this.setData({
            type_version: e.currentTarget.dataset.title
        })
    },
    is_in: function (e) {
        var _this = this;
        this.data.params.is_in = e.currentTarget.dataset.title;
        _this.setData({
            is_in: e.currentTarget.dataset.title
        })
    },
    btn: function () {
        var _this = this;
        var args = _this.data.params;
        if (!args.height) {
            wx.showToast({
                title: '请选择身高',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        if (!args.weight) {
            wx.showToast({
                title: '请选择体重',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        if (!args.station_layout) {
            wx.showToast({
                title: '请选择站姿',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        if (!args.abdomen) {
            wx.showToast({
                title: '请选择腹部',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        if (!args.type_version) {
            wx.showToast({
                title: '请选择版型',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        if (!args.is_in) {
            wx.showToast({
                title: '请选择穿着习惯',
                icon: 'loading',
                duration: 1000
            })
            return
        }
        wx.request({
            url: app.config() + '/member/autoData',
            data: args,
            header: {
                'content-type': 'application/json'
            },
            success: function (res) {
                if (res.data.status == 0) {
                    wx.setStorage({
                        key: "m_data",
                        data: res.data,
                        success: function (res) {
                            if (res.errMsg == "setStorage:ok") {
                                wx.navigateTo({
                                    url: '../result/result'
                                })
                            }
                        }
                    })
                } else {
                    wx.navigateTo({
                        url: '../tips/tips'
                    })
                }

            }
        })
    }
})